﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class news4 : System.Web.UI.UserControl
{
    private DataTable dt = null;
    public DataTable Dt { get { return dt; } set { dt = value; } }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void FetchData()
    {        
        if (dt != null)
        {
            int count = dt.Rows.Count;
            int col = 0;            
            while (count > 0) {
                if (col == 2) 
                { 
                    col = 0;
                    Panel panel = new Panel();
                    panel.Attributes.Add("Class", "news4_item_2");

                    ImageButton ibt = new ImageButton();
                    ibt.PostBackUrl = "details.aspx?id="+ dt.Rows[count-1]["news_id"].ToString();
                    ibt.ImageUrl = dt.Rows[count-1]["image_"].ToString();
                    ibt.Attributes.Add("Class","image");

                    HyperLink hplink = new HyperLink();
                    hplink.NavigateUrl = "details.aspx?id=" + dt.Rows[count-1]["news_id"].ToString();
                    hplink.Text = dt.Rows[count-1]["title"].ToString();

                    panel.Controls.Add(ibt);
                    panel.Controls.Add(hplink);
                    news4_.Controls.Add(panel);
                }
                else
                {
                    Panel panel = new Panel();
                    panel.Attributes.Add("Class", "news4_item");

                    ImageButton ibt = new ImageButton();
                    ibt.PostBackUrl = "details.aspx?id=" + dt.Rows[count-1]["news_id"].ToString();
                    ibt.ImageUrl = dt.Rows[count-1]["image_"].ToString();
                    ibt.Attributes.Add("Class", "image");

                    HyperLink hplink = new HyperLink();
                    hplink.NavigateUrl = "details.aspx?id=" + dt.Rows[count-1]["news_id"].ToString();
                    hplink.Text = dt.Rows[count-1]["title"].ToString();

                    panel.Controls.Add(ibt);
                    panel.Controls.Add(hplink);

                    news4_.Controls.Add(panel);
                }
                col++;                
                count--;               
            }               
        }
    }
}